﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="UserGroupEditorViewCtl.ascx.cs"
    Inherits="Admin_MemberAdmin_Controls_EditUserGroupViewCtl" %>
<%@ Register Assembly="Microsoft.Practices.Web.UI.WebControls" Namespace="Microsoft.Practices.Web.UI.WebControls"
    TagPrefix="pp" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<%@ Register Src="RoleAssign.ascx" TagName="RoleAssign" TagPrefix="uc1" %>
<style>
    .hidden
    {
        display: none;
    }
</style>

<script type="text/javascript" language="javascript">
    $(document).ready(function() {
        $("#roleAssign1").dialog({
            autoOpen: false,
            width: 400,
            resizable: false,
            buttons: {
                "确认": function() {
                    eval($("#<%=hiddenButton.ClientID %>").attr("href"));
                    $(this).dialog("close");
                },
                "取消": function() {
                    $(this).dialog("close");
                }
            }
        });

        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(resetDialog);
        resetDialog(null, null);
    });
    function openRoleAssign(a, b) {
        $("#roleAssign1").dialog('open');
        Sys.WebForms.PageRequestManager.getInstance().remove_endRequest(openRoleAssign);
    }

    function resetDialog(a, b) {
        $("form").append($(".ui-dialog"));
        $(".groupLink").click(function() {
            Sys.WebForms.PageRequestManager.getInstance().add_endRequest(openRoleAssign);
        });
    }
</script>

<p>
    <asp:Button ID="addLinkbutton" runat="server" OnClick="showForAdd" CausesValidation="false"
        CssClass="iconButton groupAdd" Text="添加" />
    <asp:Button ID="DeleteLinkButton" runat="server" Text="删除" CausesValidation="false"
        CssClass="iconButton groupDelete" OnClientClick="return confirm('确认删除已选择的用户组')"
        OnClick="DeleteAll" />
</p>
<pp:ObjectContainerDataSource ID="UserGroupListDataSource" runat="server" DataObjectTypeName="Ornament.MemberShip.UserGroup"
    OnSelecting="ObjectContainerDataSource1_Selecting" OnUpdated="SaveUserGroup"
    OnInserted="SaveUserGroup" OnCreating="CreateUserGroupForAllOperator" />
<asp:UpdatePanel ID="updatePanel1" runat="server">
    <ContentTemplate>
        <asp:ListView ID="ListView1" runat="server" DataSourceID="UserGroupListDataSource"
            DataKeyNames="Id" OnItemUpdated="CancelEditModel" OnItemInserted="CancelEditModel"
            OnItemEditing="ReBindRole_OnItemEditing" OnSelectedIndexChanged="SelectUserGroupForRoleAssign">
            <LayoutTemplate>
                <table class="dataGrid">
                    <caption>
                        <asp:Label ID="Label1" runat="server" Text=" 用户组信息列表"></asp:Label>
                    </caption>
                    <thead>
                        <tr>
                            <th>
                            </th>
                            <th>
                                <asp:Label ID="NameLabel" runat="server" Text="名称"></asp:Label>
                            </th>
                            <th>
                                <asp:Label ID="CommentLabel" runat="server" Text="备注"></asp:Label>
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr id="itemPlaceholder" runat="server">
                        </tr>
                    </tbody>
                    <tfoot>
                        <tr>
                            <td colspan="3">
                                <asp:DataPager ID="DataPager1" runat="server">
                                    <Fields>
                                        <asp:NextPreviousPagerField ButtonType="Link" ShowFirstPageButton="True" ShowNextPageButton="False"
                                            ShowPreviousPageButton="False" />
                                        <asp:NumericPagerField />
                                        <asp:NextPreviousPagerField ButtonType="Link" ShowLastPageButton="True" ShowNextPageButton="False"
                                            ShowPreviousPageButton="False" />
                                    </Fields>
                                </asp:DataPager>
                            </td>
                        </tr>
                    </tfoot>
                </table>
            </LayoutTemplate>
            <AlternatingItemTemplate>
                <tr class="odd">
                    <th>
                        <input type="checkbox" id="checkBoxSelected" value='<%#Eval("Id")%>' runat="server" />
                        <asp:Button ID="editUserButton" runat="server" CssClass="inputIcon groupEdit" CommandName="Edit"
                            CausesValidation="false" ToolTip="编辑用户组" />
                        <asp:Button ID="Image2" runat="server" CssClass="inputIcon groupLink" CommandName="Select"
                            AlternateText="角色选择" />
                    </th>
                    <td>
                        <asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
                    </td>
                    <td>
                        <asp:Label ID="CommentLabel" runat="server" Text='<%# Eval("Comment") %>' />
                    </td>
                </tr>
            </AlternatingItemTemplate>
            <ItemTemplate>
                <tr>
                    <th>
                        <input type="checkbox" id="checkBoxSelected" value='<%#Eval("Id")%>' runat="server" />
                        <asp:Button ID="editUserButton" runat="server" CssClass="inputIcon groupEdit" CommandName="Edit"
                            CausesValidation="false" ToolTip="编辑用户组" />
                        <asp:Button ID="Image2" runat="server" CausesValidation="false" CssClass="inputIcon groupLink"
                            CommandName="Select" AlternateText="角色选择" />
                    </th>
                    <td>
                        <asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
                    </td>
                    <td>
                        <asp:Label ID="CommentLabel" runat="server" Text='<%# Eval("Comment") %>' />
                    </td>
                </tr>
            </ItemTemplate>
            <EmptyDataTemplate>
                <table id="Table1" runat="server">
                    <tr>
                        <td>
                            <asp:Label ID="NoDataLabel" runat="server" Text="没有任何用户组"></asp:Label>
                        </td>
                    </tr>
                </table>
            </EmptyDataTemplate>
            <InsertItemTemplate>
                <tr>
                    <th>
                        <asp:Button ID="Okbutton" runat="server" CommandName="Insert" CssClass="inputIcon accept"
                            AlternateText="确认" />
                        <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" AlternateText="取消"
                            CssClass="inputIcon accept" OnClick="CancelEditModel" CausesValidation="false" />
                    </th>
                    <td>
                        <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' Width="100px" />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="请填写名称"
                            ControlToValidate="NameTextBox" Display="Dynamic" />
                    </td>
                    <td>
                        <asp:TextBox ID="CommentTextBox" runat="server" Text='<%# Bind("Comment") %>' Width="100px" />
                    </td>
                </tr>
            </InsertItemTemplate>
            <EditItemTemplate>
                <tr>
                    <th>
                        <asp:Button ID="Okbutton" runat="server" CommandName="Update" AlternateText="确认"
                            CssClass="inputIcon accept" />
                        <asp:Button ID="CancelButton" runat="server" CssClass="inputIcon cancel" CommandName="Cancel"
                            AlternateText="取消" CausesValidation="false" />
                    </th>
                    <td>
                        <asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' Width="100px" />
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="请填写名称"
                            ControlToValidate="NameTextBox" Display="Dynamic" />
                    </td>
                    <td>
                        <asp:TextBox ID="CommentTextBox" runat="server" Text='<%# Bind("Comment") %>' Width="100px" />
                    </td>
                </tr>
            </EditItemTemplate>
        </asp:ListView>
    </ContentTemplate>
</asp:UpdatePanel>
<div style="display: none" id="roleAssign1" title="角色分配">
    <asp:UpdatePanel ID="updatePanel" runat="server">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="ListView1" />
            <asp:AsyncPostBackTrigger ControlID="hiddenButton" />
        </Triggers>
        <ContentTemplate>
            <uc1:RoleAssign ID="RoleAssign1" runat="server" />
            <asp:LinkButton ID="hiddenButton" runat="server" CssClass="hidden" OnClick="SaveRoleAssign1" />
        </ContentTemplate>
    </asp:UpdatePanel>
</div>
